﻿package view.component
{
    import com.core.*;
    import consts.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import morn.core.components.*;

    public class MapPoint extends Object
    {
        private var _container:DisplayObjectContainer;
        private var _type:int = 0;
        public var gameObj:Object;
        private var _realX:Number = 0;
        private var _realY:Number = 0;
        public var role:Image;
        private var _dir:int = -1;
        private var _teamPlayer:Boolean = false;
        private var isover:Boolean = false;
        private var _visible:Boolean;
        public var isSelf:Boolean = false;

        public function MapPoint(param1:DisplayObjectContainer, param2:Object, param3:Boolean = false)
        {
            this._container = param1;
            this.gameObj = param2.gameObj.baseObj;
            if (param2.gameObj.baseObj.type == ActorType.Actor || param2.gameObj.baseObj.type == ActorType.Monster || param2.gameObj.baseObj.type == ActorType.BOSS || param2.gameObj.baseObj.type == ActorType.BigMonster)
            {
                if (param2.isMe())
                {
                    this.isSelf = true;
                    this.role = new Image("png.common.own_point");
                    param1.addChild(this.role);
                    this.role.pivotX = int(this.role.width * 0.5);
                    this.role.pivotY = 15;
                    this.dir = param2.dir;
                }
                else if (param3)
                {
                    this._teamPlayer = param3;
                    this.role = new Image("png.common.green_point");
                    param1.addChildAt(this.role, 0);
                    this.role.pivotX = int(this.role.width * 0.5);
                    this.role.pivotY = int(this.role.height * 0.5);
                }
                else
                {
                    this.role = new Image("png.common.red_point");
                    param1.addChildAt(this.role, 0);
                    this.role.pivotX = int(this.role.width * 0.5);
                    this.role.pivotY = int(this.role.height * 0.5);
                }
            }
            else
            {
                this.role = new Image("png.common.green_point");
                param1.addChildAt(this.role, 0);
                this.role.pivotX = int(this.role.width * 0.5);
                this.role.pivotY = int(this.role.height * 0.5);
            }
            this.role.addEventListener(MouseEvent.MOUSE_OVER, this.doMouse);
            this.role.addEventListener(MouseEvent.MOUSE_OUT, this.doMouse);
            return;
        }// end function

        public function changeSelf(param1:DisplayObjectContainer, param2:Object) : void
        {
            this._container = param1;
            this.gameObj = param2.gameObj.baseObj;
            param1.addChild(this.role);
            this.dir = param2.dir;
            this.role.addEventListener(MouseEvent.MOUSE_OVER, this.doMouse);
            this.role.addEventListener(MouseEvent.MOUSE_OUT, this.doMouse);
            return;
        }// end function

        public function changeOther(param1:DisplayObjectContainer, param2:Object, param3:Boolean = false) : void
        {
            this._container = param1;
            this.gameObj = param2.gameObj.baseObj;
            param1.addChildAt(this.role, 0);
            if (param2.gameObj.baseObj.type == ActorType.Actor || param2.gameObj.baseObj.type == ActorType.Monster || param2.gameObj.baseObj.type == ActorType.BOSS || param2.gameObj.baseObj.type == ActorType.BigMonster)
            {
                if (param3)
                {
                    this._teamPlayer = param3;
                    if (this.role.url != "png.common.green_point")
                    {
                        this.role.url = "png.common.green_point";
                    }
                }
                else if (this.role.url != "png.common.red_point")
                {
                    this.role.url = "png.common.red_point";
                }
            }
            else if (this.role.url != "png.common.green_point")
            {
                this.role.url = "png.common.green_point";
            }
            this.role.addEventListener(MouseEvent.MOUSE_OVER, this.doMouse);
            this.role.addEventListener(MouseEvent.MOUSE_OUT, this.doMouse);
            return;
        }// end function

        protected function doMouse(event:MouseEvent) : void
        {
            switch(event.type)
            {
                case MouseEvent.MOUSE_OVER:
                {
                    ModelProxy.change("tips", "normal", {data:this.gameObj.name, p:new Point(event.stageX, event.stageY), w:60});
                    break;
                }
                case MouseEvent.MOUSE_OUT:
                {
                    ModelProxy.change("tips", "state", "close");
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function get visible() : Boolean
        {
            return this._visible;
        }// end function

        public function set visible(param1:Boolean) : void
        {
            this._visible = param1;
            if (this.role)
            {
                this.role.visible = param1;
            }
            return;
        }// end function

        public function get teamPlayer() : Boolean
        {
            return this._teamPlayer;
        }// end function

        public function set teamPlayer(param1:Boolean) : void
        {
            if (this._teamPlayer != param1)
            {
                if (param1)
                {
                    if (this.role)
                    {
                        this.role.url = "png.common.green_point";
                    }
                }
                else if (this.role)
                {
                    this.role.url = "png.common.red_point";
                }
            }
            this._teamPlayer = param1;
            return;
        }// end function

        public function get dir() : int
        {
            return this._dir;
        }// end function

        public function set dir(param1:int) : void
        {
            var _loc_2:int = 0;
            this._dir = param1;
            if (this.role)
            {
                _loc_2 = this._dir * 45;
                this.role.rotation = _loc_2;
            }
            return;
        }// end function

        public function set x(param1:Number) : void
        {
            this._realX = param1;
            if (this.role)
            {
                this.role.x = int(param1);
            }
            return;
        }// end function

        public function get x() : Number
        {
            return this._realX;
        }// end function

        public function get y() : Number
        {
            return this._realY;
        }// end function

        public function set y(param1:Number) : void
        {
            this._realY = param1;
            if (this.role)
            {
                this.role.y = int(param1);
            }
            return;
        }// end function

        public function dispose() : void
        {
            if (this.role)
            {
                this.role.removeEventListener(MouseEvent.MOUSE_OVER, this.doMouse);
                this.role.removeEventListener(MouseEvent.MOUSE_OUT, this.doMouse);
                if (this.role.parent)
                {
                    this.role.parent.removeChild(this.role);
                }
            }
            this.gameObj = null;
            this._container = null;
            return;
        }// end function

    }
}
